package com.itheima.blog.admin.service.impl;

import com.itheima.api.client.blogAdminReport.ReportFeignClient;
import com.itheima.api.client.blogAdminReport.ReportVO;
import com.itheima.blog.admin.entity.TCategory;
import com.itheima.blog.admin.service.ITCategoryService;
import com.itheima.blog.admin.service.ReportService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;


@Service
@RequiredArgsConstructor
public class ReportServicempl implements ReportService {

    private final ReportFeignClient reportFeignClient;
    private final ITCategoryService categoryService;


    @Override
    public ReportVO classificationNumber() {
        List<TCategory> categoryList = categoryService.list();
        if (categoryList.isEmpty()) {
            return null;
        }
        List<String> nameList = categoryList.stream().map(TCategory::getName).collect(Collectors.toList());
        List<Integer> categoryIds = categoryList.stream().map(TCategory::getId).collect(Collectors.toList());

        List<Long> number = reportFeignClient.classificationNumber(categoryIds);

        ReportVO reportVO = new ReportVO();
        reportVO.setClassificationName(nameList);
        reportVO.setNumber(number);

        return reportVO;
    }


}














